package com.lifo.utils.queue.hfgooddescriptionqueue;

import com.lifo.good.bean.model.HfGoodDescription;
import com.lifo.good.service.SearchHfGoodDescriptionService;
import com.lifo.utils.queue.HuiFvQueue;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by Administrator on 2018/5/17 0017.
 */
@Slf4j
@Component
public class ProduceHfGoodDescription   {

    @Autowired
    private SearchHfGoodDescriptionService searchHfGoodDescriptionService ;


    void addHfGoodDescriptions() {
        int count = 0;
        //清洗所有没被清洗过的商品
       while (true) {
            log.debug("第{}次，获取100条",++count);
            List<HfGoodDescription> hfGoodDescriptionList = searchHfGoodDescriptionService.getHfGoodDescriptionsTop100ByIsClear(1);
            if (null != hfGoodDescriptionList && hfGoodDescriptionList.size() > 0) {
                for (HfGoodDescription hfGoodDescription : hfGoodDescriptionList) {
                    try {
                        HuiFvQueue.newInstance().arrayBlockingQueue.put(hfGoodDescription);
                    } catch (Exception e) {
                        log.error("加入待清洗商品详情数据失败==>{}", e.getMessage());
                        e.printStackTrace();
                    }
                }
            }else {
                log.debug("没查询到未清洗的商品,已终止加入商品");
                //没查询到未清洗的商品就停止
              break;
            }
       }
    }
}
